﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MediaImporter.Controls
{
    public partial class FolderSelector : UserControl
    {
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [EditorBrowsable(EditorBrowsableState.Always)]
        public override string Text
        {
            get
            {
                return label1.Text;
            }
            set
            {
                label1.Text = value;
            }
        }

        public event EventHandler PathChanged;
        
        public string SelectedPath
        {
            get
            {
                return textBox1.Text;
            }
            set
            {
                textBox1.Text = value;
            }
        }



        public FolderSelector()
        {
            InitializeComponent();
        }

        FolderBrowserDialog selector = new FolderBrowserDialog();

        private void buttonSelect_Click(object sender, EventArgs e)
        {
            selector.SelectedPath = SelectedPath;

            if (selector.ShowDialog() == DialogResult.OK && selector.SelectedPath != SelectedPath)
            {
                SelectedPath = selector.SelectedPath;
                OnPathChanged(SelectedPath);
            }
        }

        protected virtual void OnPathChanged(string SelectedPath)
        {
            if (PathChanged != null)
                PathChanged(this, EventArgs.Empty);
        }
    }
}
